function GridRow(gridTemplate, modelObject){
	this.gridTemplate = gridTemplate;
	this.modelObject = modelObject;
	this.isSelected = false;
	this.gridRowCurrentClass;
	this.gridRowContainer = null;
	this.contextMenu = null;
	this.selectedIndex = -1;
	
	this.mouseOverClass = "overGridRow";
	this.selectedClass = "selectedGridRow";
	
	this.onBeforeSelect = function(){};
	this.onSelect = function(){};
	
	
	return this;
}

// ------------------------------------------------------------------------------------------------

GridRow.prototype.renderGridRow = function(){
	if (this.gridRowContainer==null){
		this.gridRowContainer = this.gridTemplate.cloneNode(true);
	}
	
	this.gridRowCurrentClass = this.gridRowContainer.className;
	
	
	
	if (this.modelObject!=null){
		for (var property in this.modelObject){
			var element = getElement(this.gridRowContainer, property);
			if (element != null){
				element.innerHTML = this.modelObject[property];
			}
		}
	}
	
	 var gridRow = this;
	 
	 XBrowserAddHandler(this.gridRowContainer, "click", function onClick(e){
		 gridRow.onBeforeSelect();
		 gridRow.gridRowContainer.className = gridRow.selectedClass;
		 gridRow.isSelected = true;
		 
		 gridRow.onSelect();
	 });

	 XBrowserAddHandler(this.gridRowContainer, "mouseover",  function onMouseOver(e){
		XBrowserStopEventPropagation(e);
		 if(gridRow.gridRowContainer.id=="view"){
			 gridRow.gridRowContainer.className = gridRow.mouseOverClass;
		 }
		 
		if (!gridRow.isSelected){
			gridRow.gridRowContainer.className = gridRow.mouseOverClass;
		}
	 });
	 
	 XBrowserAddHandler(this.gridRowContainer, "mouseout", function onMouseOut(){
		 if (!gridRow.isSelected){
			 gridRow.gridRowContainer.className = gridRow.gridRowCurrentClass;
		 }
	 });
	 
	 XBrowserAddHandler(this.gridRowContainer, "contextmenu", function onContextMenu(e){
		 if (gridRow.isSelected){
			 if (gridRow.contextMenu != null){
				 gridRow.gridRowContainer.appendChild(gridRow.contextMenu.Template(gridRow.gridRowContainer, e));
				 XBrowserStopEventPropagation(e);
				 XBrowserStopDefaultEvents(e);
			 }
			 
			 return false;
		 }
		 
		 return false;
	 });
	 
	return this.gridRowContainer;
};



// ------------------------------------------------------------------------------------------------

GridRow.prototype.deselect = function(){
	this.isSelected = false;
	
	this.gridRowContainer.className = this.gridRowCurrentClass;
	try{
		this.gridRowContainer.removeChild(this.contextMenu.Template());
	}catch(e){}
	
};

// ------------------------------------------------------------------------------------------------

GridRow.prototype.setContextMenu = function(contextMenu) {
	this.contextMenu = contextMenu;
};